package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.ImplIotDeviceTypeEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.ImplIotDeviceTypeEntityMapper;
import com.hzhr.iot.device.entity.ImplIotDeviceTypeEntity;
import com.hzhr.iot.device.entity.ext.ImplIotDeviceTypeEntityExt;
import com.hzhr.iot.device.queryModel.custom.ImplIotDeviceTypeCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ImplIotDeviceTypeDao {
    @Autowired
    ImplIotDeviceTypeEntityMapper implIotDeviceTypeEntityMapper;
    @Autowired
    ImplIotDeviceTypeEntityCustomMapper implIotDeviceTypeEntityCustomMapper;

    public int insert(ImplIotDeviceTypeEntity record) {
        if (record == null) return 0;
        int changeCount = implIotDeviceTypeEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implIotDeviceTypeEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ImplIotDeviceTypeEntity record) {
        if (record == null) return 0;
        int changeCount = implIotDeviceTypeEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implIotDeviceTypeEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ImplIotDeviceTypeEntity selectEntity(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplIotDeviceTypeEntityExt> extList = implIotDeviceTypeEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplIotDeviceTypeEntity> selectEntityList(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplIotDeviceTypeEntityExt> extList = implIotDeviceTypeEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ImplIotDeviceTypeEntity> entityList = new ArrayList<>();
        for (ImplIotDeviceTypeEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ImplIotDeviceTypeEntityExt selectExt(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplIotDeviceTypeEntityExt> extList = implIotDeviceTypeEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplIotDeviceTypeEntityExt> selectExtList(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplIotDeviceTypeEntityExt> extList = implIotDeviceTypeEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ImplIotDeviceTypeCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = implIotDeviceTypeEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
